import React, { useEffect, useReducer } from 'react'
function reducer(state,action){
  switch(action.type){
    case 'add':
      return state+action.num
    default:
      return state
  }
}
export default function index2() {
    const [count ,dispatch] = useReducer(reducer,0)
    useEffect(()=>{
        setInterval(()=>{
            dispatch({type:'add',num:1})
        },2000)
        return ()=>{
            clearInterval()
        }
    },[])
  return (
    <div>{count}</div>
  )
}
